import Taro from '@tarojs/taro'
import { defineStore } from 'pinia'
import { $post } from '../@api'



export interface TransactionParams{
    /**
     * 承运单列表（多个或单个，数组对象格式）
     */
     bills:any
    /**
     * 用户编号
     */
     customerCode?:string

  }
  //取货接口
  export  function transaction(data:TransactionParams){
    //useTransactionStore().transactionList=data.bills;
    let billNos:string=data.bills.map((item)=>{
        return item.billNo
    }).join(',')
    // data.bills.forEach((element:any) => {
    //     billNos+=element.billNo+',';
    // });
    // billNos= billNos.substring(0, billNos.length - 1);
    $post('/selfmachine-system/takeCargo/miniTransaction',{
        billNos,
    }).then((res:any)=>{
      if(res.data.code==200){
        useTransactionStore().pickUpCode=res.data.data.map((item)=>{
            return item.ssOrderVo.pickUpCode
        })
        useTransactionStore().transactionList=res.data.data.map((item)=>{
            return {
                ...item.ssOrderVo,
                goodsInfo: item.goodsList
            }
        })
        Taro.showToast({
            icon: 'success',
            title: '取货成功！'
          })
        Taro.navigateTo({
            url: "/pages/pickUp/success",
          });
      }else{
        Taro.showToast({
            icon: 'error',
            title: '取货失败！'
          })
      }
    })
    console.log(useTransactionStore().transactionList,'transactionList');

  }
  interface transactionInfoStates{
    transactionList:any,
    pickUpCode:any,
  }
  const useTransactionStore = defineStore("transactionInfo", {
    // 持久化存储插件其他配置
    state: (): transactionInfoStates => ({
        transactionList:[],
        pickUpCode:[],
    }),
    actions: {
    },

    getters: {

    },
})
export default useTransactionStore

